﻿using UnityEngine;
using System.Collections;

public class EnemyGuideMovement : MonoBehaviour {
	// THIS SCRIPT CURRENTLY ONLY MOVES THE ENEMYGUIDE UP
	//WHAT NEEDS TO BE FIXED: Need to make it istantiate EnemyGuide with a different name, and then have EnemyGuide recognize when the player enters the new gameObject's collider. That should trigger the EnemyGuide to destroy the new instantiated version so the player stop moving. The player should follow the newer version of EnemyGuide.
	
	
	// Variables
	public Transform enemyGuide;
	
	private float position;

	//private bool playerTouch;
	
	/* THIS WILL BE USED TO CONTROL ENEMYGUIDE SPEED IF NEEDED
	public float wanderSpeed = 2;
*/
	
	// Used to determine how far the enemy guide moves
	private float totalWalkDistance;


	// Use this for initialization
	void Start () {
		findPosition ();
	}

	void Update(){
		//OnCollisionEnter ();
	}

	/*
	void OnCollisionEnter(Collision col){
		if(col.gameObject.name == "enemy"){
			playerTouch = true;
		}
	}
	*/
	
	// Finds position of enemyGuide
	private void findPosition(){
		position = enemyGuide.position.y;
		
		Debug.Log ("Enemy Y position: " + position);
		Debug.Log ("Finished! Calling Walk Repeat");

		//walkRepeat ();
		enemyGuideCloneWalk ();
	}
	
	// Repeats walk commands after 5 seconds. Starts after 3 seconds
	/*
	private void walkRepeat(){
		if (playerTouch == true) {
			InvokeRepeating ("enemyGuideCloneWalk", 3, 13f);
		}
	}
	*/
	
	private void enemyGuideCloneWalk(){
		// Distance Generator
		float walkDistance = Random.Range (5f, 10f);
		totalWalkDistance = walkDistance + position;
		Debug.Log ("Distance generated up: " + totalWalkDistance + ".");

		enemyGuide.transform.Translate (new Vector2 (0, totalWalkDistance));
}
}